/*
		ServEngine framework library
		A library to fast develop JEE online applications
	
		Copyright 2008 José Ignacio de Córdoba Álvaro

		Licensed under the Apache License, Version 2.0 (the "License");
		you may not use this file except in compliance with the License.
		You may obtain a copy of the License at

				http://www.apache.org/licenses/LICENSE-2.0

		Unless required by applicable law or agreed to in writing, software
		distributed under the License is distributed on an "AS IS" BASIS,
		WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
		See the License for the specific language governing permissions and
		limitations under the License.
	
		Jose Ignacio de Cordoba Alvaro
		http://ignacio.decordoba.com
*/

package com.servengine.user;

import com.servengine.struts.ValidatorForm;

import java.util.Date;
import java.util.Map;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

/**
 * Action form corresponding to User EJB
 * @see UserActions
 * @see UserAdminActions
 */
public class UserActionForm extends ValidatorForm
{
//	private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(UserActionForm.class.getName());
	protected String portalid; // Para el proceso de login.
	private Integer id;
	protected String userid, firstname, lastname, lastname2, email, password;// Para el login
	protected String newpassword, newpassword2;// Para el alta y las preferencias
	protected Date creationdate;//, lastLogin;
	protected Integer[] roleIds; // Para facilitar el set desde interfaz JSP.
	protected Map<String,String> extraUserdataMap;
//	protected Collection<ExtraUserdataSBean> extrauserdata;
	protected boolean remembersession;
	protected org.apache.struts.upload.FormFile pictureFile;
	protected String locale;
	
	public void setPortalid(String value)
	{
		portalid = value;
	}

	public String getPortalid()
	{
		return portalid;
	}

	public String getUserid()
	{
		return userid;
	}
	
	public void setUserid(String userid)
	{
	  this.userid = userid==null?null:userid.toLowerCase();
	}

	/**
	 * Convenience method returning firstName lastName lastname2
	 * @return firstname+" "+lastName+" "+lastname2 (null values are substitued by "")
	 */
	public String getName()
	{
	  return (firstname == null ? "" : firstname) + (lastname == null ? "" : " "+lastname) + 
	    (lastname2 == null ? "" : " "+lastname2);
	}

	public void setFirstname(String firstname)
	{
		this.firstname = firstname;
	}

	public String getFirstname()
	{
		return firstname;
	}

	public void setLastname(String lastname)
	{
		this.lastname = lastname;
	}

	public String getLastname()
	{
		return lastname;
	}

	public void setLastname2(String lastname2)
	{
		this.lastname2 = lastname2;
	}

	public String getLastname2()
	{
		return lastname2;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	public String getEmail()
	{
		return email;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getPassword()
	{
		return password;
	}

	public void setNewpassword(String newpassword)
	{
		this.newpassword = newpassword;
	}

	public String getNewpassword()
	{
		return newpassword;
	}

	public void setNewpassword2(String newpassword2)
	{
		this.newpassword2 = newpassword2;
	}

	public String getNewpassword2()
	{
		return newpassword2;
	}

	public void setRoleIds(Integer[] roleIds)
	{
		this.roleIds = roleIds;
	}

	public Integer[] getRoleIds()
	{
		return roleIds;
	}

	public void setCreationdate(Date creationdate)
	{
		this.creationdate = creationdate;
	}

	public Date getCreationdate()
	{
		return creationdate;
	}

	public Map<String,String> getExtraUserdataMap()
	{
		return extraUserdataMap;
	}

	public void setExtraUserdataMap(Map<String,String> value)
	{
		extraUserdataMap = value;
	}

	public String getExtradatum(String name)
	{
		return extraUserdataMap==null?null:extraUserdataMap.get(name);
	}

	public void setExtradatum(String fieldname, String value)
	{
		extraUserdataMap.put(fieldname,value);
	}

	public void setRemembersession(boolean remembersession)
	{
		this.remembersession = remembersession;
	}

	public boolean isRemembersession()
	{
		return remembersession;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request)
	{
		super.reset(mapping,request);
		roleIds=new Integer[0];
		extraUserdataMap = new HashMap<String,String>();
	}

	public void setPictureFile(FormFile pictureFile)
	{
		this.pictureFile = pictureFile;
	}

	public FormFile getPictureFile()
	{
		return pictureFile;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}

	public Integer getId()
	{
		return id;
	}

	public void setLocale(String locale)
	{
		this.locale = locale;
	}

	public String getLocale()
	{
		return locale;
	}
}
